package vip.liux.front.adapter.controller.chat;

import org.springframework.web.bind.annotation.*;
import vip.liux.core.current.ICurrentUser;
import vip.liux.front.application.service.chat.IConversationAppService;
import vip.liux.front.application.service.chat.dtos.conversations.ChatConversationDto;
import vip.liux.front.application.service.chat.dtos.conversations.GetConversationInput;
import vip.liux.front.application.service.chat.dtos.conversations.MarkConversationAsReadInput;
import vip.liux.front.application.service.chat.dtos.messages.SendMessageInput;

@RestController
@RequestMapping("/api/chat/conversation")
public class ConversationController {

    private final IConversationAppService conversationAppService;
    private final ICurrentUser<Long> currentUser;

    public ConversationController(IConversationAppService conversationAppService, ICurrentUser<Long> currentUser) {
        this.conversationAppService = conversationAppService;
        this.currentUser = currentUser;
    }

    /**
     * 发送消息.
     *
     * @param input 输入参数
     */
    @PostMapping("/send-message")
    public void sendMessage(@RequestBody SendMessageInput input) {
        conversationAppService.sendMessage(input, currentUser.getId());
    }

    /**
     * 获取会话.
     *
     * @param input 输入参数
     * @return 会话
     */
    @GetMapping("/conversations")
    public ChatConversationDto GetConversationAsync(GetConversationInput input) {
        return conversationAppService.getConversation(input, currentUser.getId());
    }

    /**
     * 标记会话为已读.
     *
     * @param input 输入参数
     */
    @PostMapping("/mark-conversation-as-read")
    public void markConversationAsReadAsync(@RequestBody MarkConversationAsReadInput input) {
        conversationAppService.markConversationAsReadAsync(input, currentUser.getId());
    }
}
